//
//  NSAttributedString+Format.m
//  RobNewGrain
//
//  Created by 唐可雄 on 16/7/2.
//  Copyright © 2016年 swustyc. All rights reserved.
//

#import "NSAttributedString+Format.h"

#import <UIKit/UIKit.h>

@implementation NSAttributedString (Format)

+ (NSAttributedString *)strAttrWithNewPrice:(double)priceNew oldPrice:(double)priceOld {
    NSString *str1 = [NSString stringWithFormat:@"¥%.02lf", priceNew];
    NSString *str2 = [NSString stringWithFormat:@"¥%.02lf", priceOld];
    
    NSString *str = [NSString stringWithFormat:@"%@%@", str1, str2];
    
    NSRange range1 = [str rangeOfString:str1];
    NSMutableAttributedString *strAttr = [[NSMutableAttributedString alloc] initWithString:str];
    [strAttr addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range1];
    [strAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.f] range:range1];
    NSRange range2 = NSMakeRange(str1.length, str2.length);
    [strAttr addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:range2];
    [strAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11.f] range:range2];
    [strAttr addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:range2];
    return strAttr;
}

+ (NSAttributedString *)strAttrWithPrice:(double)price {
    NSString *str = [NSString stringWithFormat:@"¥%.02lf", price];
    
    NSMutableAttributedString *strAttr = [[NSMutableAttributedString alloc] initWithString:str];
    [strAttr addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:[str rangeOfString:str]];
    [strAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.f] range:[str rangeOfString:str]];
    
    return strAttr;
}

@end
